//
// Created by lain on 24-10-23.
//

#include "queue.h"

Queue::Queue() {
    front = rear = 0;
    for(int & i : item)
        i = -1;
}

bool Queue::QueueIsEmpty() const {
    if(front == rear)
        return true;
    return false;
}
bool Queue::QueueIsFull() const {
    if((rear+1)%QUEUE_SIZE == front)
        return true;
    return false;
}
void Queue::enterQueue(const int& e) {
    if(QueueIsFull())
        return;
    rear = (rear+1)%QUEUE_SIZE;
    item[rear]=e;
}
void Queue::leaveQueue(int&e) {
    if(QueueIsEmpty())
        return;
    front = (front+1)%QUEUE_SIZE;
    e = item[front];
}
void Queue::clearQueue() {
    front = rear = 0;
}
void Queue::getHead(int& e) const {
    if(QueueIsEmpty())
        return;
    e = item[(front+1)%QUEUE_SIZE];
}
